<?php
  require '../../include/library.inc.php';
  require '../../include/admin_login.inc.php';
  require '../../include/paging.inc.php';
  
  $category_id = intval($_GET['cat']);
  $lang = 1;
  $sql = "SELECT
			 c.album_id,
			  c.order_number,
			  c.published,
			  
			  
			  d.title
			  
			  
		  FROM
			  album AS c,
			  album_description AS d
		  WHERE
		  
			  c.album_id = d.album_id
			  
			  AND
			  
			  d.lang_id = '".$lang."'
			";
			
  if ($category_id) {
	  $sql =	"SELECT
			  c.album_id,
			  c.order_number,
			  c.published,
			 
			  d.title	
		  FROM
			  album AS c,
			  album_description AS d,
			  album_to_category AS r
		  WHERE
		  
			  c.album_id = d.album_id
			  AND
			  d.lang_id = '".$lang."'
			  AND
			  c.album_id = r.album_id
			  AND
			  category_id = '".$category_id."'
			";
	  
  }
  
  
  if (!isset($_GET['sort'])) $_GET['sort'] = 1;
  if (!isset($_GET['sortBy'])) $_GET['sortBy'] = 2;
  
  $paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(2=>"Подредба"), 10);
  $result = $paging->query();
	  
	  head_admin("Фото Албуми");
  ?>
<?php if ($_SESSION['message']) { ?>

	<div class="message green">
  		<?=$_SESSION['message']?>
	</div>
<?php unset($_SESSION['message']); } ?>
	<div class="topbuttons"> <a href="album_new.php">Добави нов фото албум</a> </div>
	<h3>Албуми (
	  <?=$paging->count()?>
      )</h3>
<table id="listing" width="100%" cellpadding="0" cellspacing="0">
  <thead>
    <tr>
      <td></td>
      <td>Име</td>
      <td>Публикуван</td>
       <?php if(!$category_id){?><td>Подредба</td><?php }?>
      <td>Действия</td>
	</tr>
  </thead>
  <tbody>
    <?php
				
				
				$i=1;
				while ($row = mysql_fetch_object($result)) {				  
			  ?>
	<tr class="<?=(($i%2)?"none":"zebra")?>">
		<td>
        	<a href="album_edit.php?album_id=<?=$row->album_id?>"  rel="logos"><img style="height:100px" class="thumb" src="<?=getImage('../albums/'.$row->album_id.'/thumbnail/')?>" /></a>
        </td>
		<td>
        	<a href="album_edit.php?album_id=<?=$row->album_id?>" title="Редактирай">
               <?=sth($row->title)?></a>
        </td>
        
		<td class="switch"><?php if ($row->published) { ?>
        	<a href="album_publish.php?album_id=<?=$row->album_id?>&publish=0" class="turn_on" name="turn_on" title="Спри"></a>
        <?php } else { ?>
       	 	<a href="album_publish.php?album_id=<?=$row->album_id?>&publish=1" class="turn_off" name="turn_off" title="Публикувай"></a>
        <?php } ?>
        </td>
        <?php if(!$category_id){?> 
		<td class="sort"><?php if ($i != 1) { ?>
        	<a name="Up" class="sorting_up" title="Нагоре" href="album_direction.php?album_id=<?=$row->album_id?>&direction=1"></a>
        <?php } ?>
        <?php if ($i != ($paging->count())) { ?>
        	<a name="Down" class="sorting_down" title="Надолу" href="album_direction.php?album_id=<?=$row->album_id?>&direction=-1"></a>
        <?php } ?>
        &nbsp;<!--ie6 bug--></td>
        <?php }?>
        
		<td class="icons">
        	<a name="Top" class="sorting_top" title="Top" href="album_direction.php?album_id=<?=$row->album_id?>&top=1">Top</a> <a href="album_edit.php?album_id=<?=$row->album_id?>" class="edit" title="Редактирай">Редактирай</a> 
            <a onClick="if (window.confirm('Сигурен ли си, че искаш да изтриеш <?=sth($row->title)?>?')) { document.location='album_del.php?album_id=<?=$row->album_id?>'; return false; }" class="delete" title="Изтрий">Изтрий</a>
        </td>
	</tr>
		<?php
                    $i++;    
                  } 
               ?>
  </tbody>
</table>
<div class="pagingwrap">
	<div class="paging">
    	<?=$paging->display()?>
	</div>
</div>
<?php
	  foot_admin(); 
  ?>
